import {
    defineStore
} from 'pinia'
import {
    login
} from '@/api/login.js'

export const userStore = defineStore('userStore', {
    state() {
        return {
            user: {},
            token: window.localStorage.getItem('token') || ''
        }
    },
    getters: {
        getUser: state => state.user,
        getToken: state => state.token
    },
    actions: {
        async login(params) {
            const {
                data = {}
            } = await login(params)
            this.user = data;
            this.token = data.access_token;
            window.localStorage.setItem('token', data.access_token);
            console.log('用户数据', data)
        },
    }
})